package emby;

import emby.lang.Scope;
import emby.writer.IEmbyCodifier;

/**
 * Represents a single node inside an Abstract Syntax Tree.
 * @author Justin
 */
public abstract class ASTNode {
	/**
	 * The line number that the code was found on.
	 * This variable is used for error-reporting purposes (ex. Syntax error on line 27!)
	 */
	protected int lineNum;

	protected ASTNode(int lineNumber){
		lineNum = lineNumber;
	}

	/**
	 * Create an ASTNode with the default line number.
	 */
	protected ASTNode(){
		lineNum = -1;
	}

	/**
	 * Sets the line number of this node. Should only be called by the parser.
	 * @param i
	 */
	public void setLine(int i){
		lineNum = i;
	}

	public int getLine(){
		return lineNum;
	}

	/**
	 * Evaluate this expression within the given scope.
	 * Emby programs begin execution by calling eval on the root
	 * of the AST. The root node may recursively call eval on its
	 * child nodes.
	 * @param s
	 * @return the result of evaluation
	 */
	public abstract Object eval(Scope s);
	
	/**
	 * Used for converting an emby syntax tree node back into
	 * code in text (or another) form
	 * @param ec
	 */
	public abstract void codify(IEmbyCodifier ec);
}
